import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const SecurityTrain = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    let dataList = {
        pageSize: 10,
        hideInSearch: true,
        params: { securityTrainUuid: oneData.uuid },
        initialValues: { securityTrainUuid: oneData.uuid },
        get: API_LIST()['getSecurityTrainAttachment'],
        added: 'posSecurityTrainAttachment',
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />],
        columns: [
            {
                title: 'securityTrainUuid',
                dataIndex: 'securityTrainUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                title: '原始文件名',
                dataIndex: ['attachment', 'originalName'],
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '文件附件',
                valueType: 'upload',
                valueFile: [1, 2, 3, 4],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },

            commonTableList.createUserName,
            commonTableList.createTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { attachment } = record
                    return [
                        attachment?.fileUrl && (
                            <AnnexButton
                                OptionsEvent={OptionsEvent}
                                key="see"
                                url={attachment.fileUrl}
                                title="查看附件"
                            />
                        ),
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url="SecurityTrainAttachment"
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }

    return dataList
}
